//第一步：安装
//第二步：引入并声明使用
//第三步：必须往外暴露一个路由器对象
//第四步：必须在main文件当中Vue的配置对象里面注入你的路由器对象
import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
Vue.use(VueRouter)

//先把原来的push方法保存起来
const originPush = VueRouter.prototype.push
const originReplace = VueRouter.prototype.replace
//把原来的push修改为另外一个方法
VueRouter.prototype.push = function(location,resolved,rejected){
  if(resolved === undefined && rejected === undefined){
    return originPush.call(this,location).catch(() => {})
  }else{
    return originPush.call(this,location,resolved,rejected)
  }
}

VueRouter.prototype.replace = function(location,resolved,rejected){
  if(resolved === undefined && rejected === undefined){
    return originReplace.call(this,location).catch(() => {})
  }else{
    return originReplace.call(this,location,resolved,rejected)
  }
}

export default new VueRouter({
  // mode:'history',
  routes,
  scrollBehavior (to, from, savedPosition) {
    return { x: 0, y: 0 }
  }
})

